#include <netinet/in.h>
#include <stdio.h>
#include <stdlib.h>
#include "network.h"
#include "common.h"



int main() {
  int count = 0;
  struct sockaddr_in client_adress;
  int server_socket_id = server_socket_open(PORT);

  while (1) {
    int socket_id = server_socket_accept(server_socket_id, &client_adress);
    count++;
    printf("Received connection from %s. count=%d\n", inet_ntoa(client_adress.sin_addr), count);
    int data = htonl(count);
    write(socket_id, &data, sizeof(count));
    error_if(close(socket_id) == -1, "Unanable to close");
  }
  return 0;
}

